<template>
  <view class="container">
    <view class="main-content">
      <view class="header">
        <text class="title">听鸽共享充电桩</text>
        <view class="pile-details">
          <text class="pile-id">桩号881116045</text>
          <text class="pile-location">车位号: A01</text>
        </view>
      </view>

      <view class="pile-status">
        <image class="pile-image" src="/static/images/pile.png" />
        <view class="status-display">
          <view :class="['status-dot', getStatusClass(piles[0].status)]"></view>
          <text class="status-text">{{ getStatusText(piles[0].status) }}</text>
        </view>
      </view>

         
    </view>

 <view class="action-card">
      <view class="action-item" @click="toggleCharge">
       <uni-icons type="link" size="30"></uni-icons>

        <!-- <image class="action-icon" :src="isCharging ? '/static/images/icon-stop.png' : '/static/images/icon-start.png'" /> -->
        <text>{{ isCharging ? '结束充电' : '开始充电' }}</text>
      </view>
      <view class="action-item" @click="notifyTow">
       <uni-icons type="info" size="30"></uni-icons>
        <!-- <image class="action-icon" src="/static/images/icon-notify.png" /> -->
        <text>通知挪车</text>
      </view>
      <view class="action-item" @click="reserveCharge">
       <uni-icons type="calendar" size="30"></uni-icons>
        <!-- <image class="action-icon" src="/static/images/icon-reserve.png" /> -->
        <text>预约充电</text>
      </view>
      <view class="action-item" @click="goToSettings">
       <uni-icons type="gear" size="30"></uni-icons>
        <!-- <image class="action-icon" src="/static/images/icon-settings.png" /> -->
        <text>设置</text>
      </view>
    </view>

 

  </view>
</template>

<script>
export default {
  data() {
    return {
      piles: [
        { id: 'SN001', location: 'A01', status: 'idle' },
      
      ],
      vin: '12313123132', // 车辆VIN码
      isCharging: false,
    };
  },
  methods: {
    getStatusClass(status) {
      if (status === 'idle') return 'status-idle';
      if (status === 'charging') return 'status-charging';
      if (status === 'occupied') return 'status-occupied';
      return '';
    },
    getStatusText(status) {
      if (status === 'idle') return '空闲';
      if (status === 'charging') return '充电中';
      if (status === 'occupied') return '占位';
      return '';
    },
    toggleCharge() {
      this.isCharging = !this.isCharging;
      this.piles[0].status = this.isCharging ? 'charging' : 'idle';
    },
    notifyTow() {
      uni.showToast({
        title: '已短信通知车主',
        icon: 'none',
      });
    },
    reserveCharge() {
      uni.showModal({
        title: '预约充电',
        content: '请选择预约时间段',
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定');
          } else if (res.cancel) {
            console.log('用户点击取消');
          }
        }
      });
    },
    goToSettings(pileId) {
      uni.navigateTo({ url: `/pages/shared-charging/settings?id=${pileId}` });
    },
    bindVin() {
      // 这里可以跳转到绑定车辆的页面
      console.log('跳转到绑定车辆页面');
      // 模拟绑定成功后
      // this.vin = 'ABCDEFG123456';
    },
  },
};
</script>

<style scoped>
.container {
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  height: 100%;
}
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
}
.header {
  width: 90%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 20px;
}
.title {
  font-size: 18px;
}
.pile-details {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 5px;
}
.vin-container {
  margin-top: 10px;
  width: 100%;
  /*display: flex;*/
  justify-content: center;
}
.vin-display {
  display: flex;
  align-items: center;
  gap: 5px;
  /*background-color: #f0f0f0;*/
  padding: 5px 10px;
  border-radius: 10px;
}
.vin-label {
  font-size: 14px;
  color: #888;
}
.vin-number {
  font-size: 14px;
  color: #333;
}
.vin-bind .bind-button {
  font-size: 14px;
  background-color: #ff6a00;
  color: white;
  border: none;
  padding: 5px 15px;
  border-radius: 15px;
}
.pile-id,
.pile-location {
  font-size: 14px;
  color: #888;
  background-color: #f0f0f0;
  padding: 2px 8px;
  border-radius: 10px;
}
.pile-status {
  align-items: center;
  display: flex;
  flex-direction: column;
  margin-bottom: 20px;
}
.pile-image {
  width: 150px;
  height: 150px;
  margin-bottom: 10px;
}
.status-text {
  font-size: 16px;
}
.service-card {
  background-color: #fff5e6;
  border: 1px solid #ffe1b3;
  border-radius: 8px;
  padding: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 20px;
}
.service-info {
  display: flex;
  flex-direction: column;
}
.service-title {
  font-size: 16px;
  font-weight: bold;
}
.service-desc {
  font-size: 12px;
  color: #888;
}
.service-button {
  background-color: #ff6a00;
  color: white;
  border-radius: 15px;
  padding: 5px 15px;
  font-size: 14px;
}
.action-card {
  background-color: #ffffff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.05);
  display: flex;
  justify-content: space-around;
  width: 100%;
  box-sizing: border-box;
  flex-shrink: 0;
}
.action-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.action-icon {
  width: 40px;
  height: 40px;
  margin-bottom: 5px;
}
.status-display {
  display: flex;
  align-items: center;
  gap: 8px;
}
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.status-idle {
  background-color: #28a745;
}
.status-charging {
  background-color: #ffc107;
}
.status-occupied {
  background-color: #dc3545;
}
.quick-actions {
    display: flex;
    justify-content: space-around;
    width: 100%;
}
</style>